package com.club.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.club.common.security.MyPasswordEncoder;
import com.club.entity.R;
import com.club.entity.TClubPic;
import com.club.mapper.TClubPicMapper;
import com.club.service.SysUserService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chaochao(vx : zhangfec)
 */
@RequiredArgsConstructor
@RestController
public class TestController {

    private final MyPasswordEncoder myPasswordEncoder;

    private final SysUserService sysUserService;

    private final TClubPicMapper tClubPicMapper;

    @PreAuthorize("hasRole('admin')")
    @GetMapping("/test")
    public R test() {
        return R.ok("测试成功");
    }

    @GetMapping("/password")
    public R password() {
        String password = myPasswordEncoder.encode("123456");
        System.out.println("password:" + password);
        return R.ok();
    }

    @PreAuthorize("hasAnyAuthority('system:user:list')")
    @GetMapping("/user/list")
    public R userList() {
        Map<String, Object> userList = new HashMap<String, Object>();
        userList.put("userList", sysUserService.list());
        return R.ok(userList);
    }


    @GetMapping("/all/queryClubPic")
    public R queryClubPic() {
        List<TClubPic> filepath = tClubPicMapper.selectList(new QueryWrapper<TClubPic>().like("filepath", ""));
        Map<String, Object> map = new HashMap<>();
        map.put("file", filepath);
        return R.ok(map);
    }

}
